package main

import "fmt"

func main() {

	fmt.Println(factorial1(10))
	fmt.Println(factorial(10))
	numarr(13)
}

func numarr(n int) {
	//打印空格
	kg := func(a int) {
		for i := 1; i <= a; i++ {
			fmt.Print("   ") //注：空格数与下面的%d数值一样
		}
	}

	//按数字大小打印为一行
	print1 := func(n int) {
		for i := n; i > 0; i-- {
			fmt.Printf("%3d", i)
		}
		fmt.Println()
	}

	for i := 1; i <= n; i++ {
		kg(n - i)
		print1(i) //调用打印行
	}
}

func factorial(n int) int {
	product := 1
	for i := 1; i <= n; i++ {
		product *= i
	}
	return product
}

func factorial1(n int) int {
	if n == 1 {
		return 1
	}
	return n * factorial1(n-1)
}

// 批改意见
// 1. 没有考虑阶乘中n<0或n=0的特殊情况